package com.system.core.plugins.mybatis.custom;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.TopLevelClass;

import lombok.experimental.UtilityClass;

@UtilityClass
public class ClassModify {
	
	public void setterComment(Method method,IntrospectedColumn introspectedColumn) {
		List<String> doclist = method.getJavaDocLines();
		
		String paranName = method.getParameters().get(0).getName();
		
		doclist.clear();
		doclist.add("/**");
		if(StringUtils.isBlank(introspectedColumn.getRemarks())) {
			doclist.add(" * 设置"+introspectedColumn.getJavaProperty());
		} else {
			doclist.add(" * 设置"+introspectedColumn.getRemarks());
		}
		doclist.add(" * @param "+paranName+" "+introspectedColumn.getRemarks());
//		doclist.add(" * @mbggenerated");
		doclist.add(" */");
	}
	
	public void methodComment(Method method,IntrospectedColumn introspectedColumn) {
		List<String> doclist = method.getJavaDocLines();
		doclist.clear();
		doclist.add("/**");
		if(StringUtils.isBlank(introspectedColumn.getRemarks())) {
			doclist.add(" * 获取"+introspectedColumn.getJavaProperty());
			doclist.add(" * @return "+introspectedColumn.getJavaProperty());
		} else {
			doclist.add(" * 获取"+introspectedColumn.getRemarks());
			doclist.add(" * @return "+introspectedColumn.getRemarks());
		}
//		doclist.add(" * @mbggenerated");
		doclist.add(" */");
	}

	public void lombokClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
		topLevelClass.addImportedType("io.swagger.v3.oas.annotations.media.Schema");
		topLevelClass.addImportedType("jakarta.validation.constraints.Size");
		
//		topLevelClass.addImportedType("lombok.Builder");
		topLevelClass.addImportedType("lombok.Data");
		
//		topLevelClass.addAnnotation("@Builder");
		topLevelClass.addAnnotation("@Data");
		
		List<String> docs = topLevelClass.getJavaDocLines();
		docs.clear();
		docs.add("/**");
		docs.add(" *");
		docs.add(" * "+introspectedTable.getRemarks());
		docs.add(" *");
		docs.add(" * @author 江路");
		docs.add(" **/");
	}
}
